package com.jxw.launcher;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListAdapter;
import com.jxw.launcher.AppInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* loaded from: classes.dex */
public class APPControl {
    private GridView freqListView;
    private Context mContext;
    private OnItemClickLinser mOnItemClick;
    private ListViewAdapter mVpAdapter;
    private List<AppInfo> mlistAppInfo = null;

    /* loaded from: classes.dex */
    public interface OnItemClickLinser {
        void onItemClick(String str);
    }

    public APPControl(Context context, View view) {
        this.mContext = context;
        initView(view);
        initData();
        new Thread(new Runnable() { // from class: com.jxw.launcher.APPControl.1
            @Override // java.lang.Runnable
            public void run() {
                APPControl.this.queryAppInfo();
            }
        }).start();
    }

    private void initView(View view) {
        this.freqListView = (GridView) view.findViewById(R.id.gridView_id);
        this.mlistAppInfo = new ArrayList();
    }

    private void initData() {
        this.mVpAdapter = new ListViewAdapter(this.mContext, this.mlistAppInfo);
        this.freqListView.setAdapter((ListAdapter) this.mVpAdapter);
        this.freqListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: com.jxw.launcher.APPControl.2
            @Override // android.widget.AdapterView.OnItemClickListener
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                if (APPControl.this.mOnItemClick != null) {
                    APPControl.this.mOnItemClick.onItemClick(((AppInfo) APPControl.this.mlistAppInfo.get(i)).getPkgName());
                }
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void queryAppInfo() {
        PackageManager packageManager = this.mContext.getPackageManager();
        Intent intent = new Intent("android.intent.action.MAIN", (Uri) null);
        intent.addCategory("android.intent.category.LAUNCHER");
        List<ResolveInfo> queryIntentActivities = packageManager.queryIntentActivities(intent, 0);
        Collections.sort(queryIntentActivities, new ResolveInfo.DisplayNameComparator(packageManager));
        List<AppInfo> list = this.mlistAppInfo;
        if (list != null) {
            list.clear();
            for (ResolveInfo resolveInfo : queryIntentActivities) {
                String str = resolveInfo.activityInfo.name;
                String str2 = resolveInfo.activityInfo.packageName;
                String str3 = (String) resolveInfo.loadLabel(packageManager);
                Drawable loadIcon = resolveInfo.loadIcon(packageManager);
                Intent intent2 = new Intent();
                intent2.setComponent(new ComponentName(str2, str));
                Log.i("queryAppInfo: ", str2 + ":" + str3);
                if (!str2.contains("jxw")) {
                    this.mlistAppInfo.add(new AppInfo.Builder().appLabel(str3).pkgName(str2).appIcon(loadIcon).intent(intent2).build());
                    Log.e("gwj:", str2 + "");
                }
            }
        }
        this.freqListView.post(new Runnable() { // from class: com.jxw.launcher.APPControl.3
            @Override // java.lang.Runnable
            public void run() {
                APPControl.this.mVpAdapter.notifyDataSetChanged();
            }
        });
    }

    private void updateAppData() {
        queryAppInfo();
        this.mVpAdapter.notifyDataSetChanged();
    }

    public void setOnItemClick(OnItemClickLinser onItemClickLinser) {
        this.mOnItemClick = onItemClickLinser;
    }
}
